package com.example.grafstock_upload;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {
	
	private Context mContext;
	
	private LayoutInflater inflater;

	public ImageAdapter(Context c) {
		inflater = LayoutInflater.from(c);
		mContext = c;
		
//		mContext = c;
	}

	public int getCount() {
		return ImageManager.getInstancia(mContext.getResources(), null).getCount();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
        if(v == null) {
            v = inflater.inflate(R.layout.grid_layout, parent, false);
            v.setTag(R.id.picture, v.findViewById(R.id.picture));
            v.setTag(R.id.text, v.findViewById(R.id.text));
        }		
		
        ImageView picture = (ImageView)v.getTag(R.id.picture);
        TextView name = (TextView)v.getTag(R.id.text);

//        Item item = (Item)getItem(position);

//		ImageView imageView;
//		if (convertView == null) {  // if it's not recycled, initialize some attributes
//			imageView = new ImageView(mContext);
//			imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
//			imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//			imageView.setPadding(8, 8, 8, 8);
//		} else {
//			imageView = (ImageView) convertView;
//		}
        picture.setImageBitmap(ImageManager.getInstancia(mContext.getResources(), null).getImagens().get(position));
//        if(position == ImageManager.getInstancia(mContext.getResources(), null).getCount() - 1) {
        	name.setVisibility(View.INVISIBLE);
//        } else {
//        	name.setText("Teste");        	
//        }
		
//		
//		imageView.setImageBitmap(ImageManager.getImagens().get(position));
//		
//		
		
		return v;
	}

}